<template>
  <div>Markdown查看器</div>
  <MarkdownViewer v-if="content.length>0" :md-text="content"></MarkdownViewer>
</template>

<script>
import {getFile} from "@/api/file";
import MarkdownViewer from "@/components/MarkdownViewer";

export default {
  name: "Markdown",
  components: {MarkdownViewer},
  data() {
    return {
      path: "",
      content:"",
    }
  },
  methods: {
    getPath() {
      this.path = this.getQueryString("path")
    },
    getQueryString(name) {
      let reg = `(^|&)${name}=([^&]*)(&|$)`
      let r = window.location.search.substr(1).match(reg);
      if (r != null) return unescape(r[2]);
      return null;
    },
    async showContent() {
      // let res = await getFile({path: this.path})
      // this.content=res.data

      this.content="```java\n" +
          "public class HelloWorld {\n" +
          "\n" +
          "    public static void main(String[] args) {\n" +
          "        System.out.println(\"Hello World!\");\n" +
          "    }\n" +
          "\n" +
          "}\n" +
          "\n" +
          "```\n" +
          "\n" +
          "```graphviz\n" +
          "digraph finite_state_machine {\n" +
          "    rankdir=LR;\n" +
          "    size=\"8,5\"\n" +
          "    node [shape = doublecircle]; S;\n" +
          "    node [shape = point ]; qi\n" +
          "\n" +
          "    node [shape = circle];\n" +
          "    qi -> S;\n" +
          "    S  -> q1 [ label = \"a\" ];\n" +
          "    S  -> S  [ label = \"a\" ];\n" +
          "    q1 -> S  [ label = \"a\" ];\n" +
          "    q1 -> q2 [ label = \"ddb\" ];\n" +
          "    q2 -> q1 [ label = \"b\" ];\n" +
          "    q2 -> q2 [ label = \"b\" ];\n" +
          "}\n" +
          "```"
      console.log(this.content)
    }
  },
  mounted() {
    this.getPath()
    this.showContent()
  }
}
</script>

<style scoped>

</style>